<template>
  <div>
    <el-form :model="pageForm" inline>
      <el-form-item label="仓库：">
        <el-select v-model="pageForm.warehouseId" clearable>
          <el-option :label="item.name" :value="item.id" v-for="item in store.NewHouseList" :key="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="父订单号：">
        <el-input v-model="pageForm.tid" clearable />
      </el-form-item>
      <el-form-item label="子订单号：">
        <el-input v-model="pageForm.oid" clearable />
      </el-form-item>
      <el-form-item label="质检结果:">
        <el-select v-model="pageForm.isPass" clearable>
          <el-option label="质检通过" :value="1" />
          <el-option label="质检不通过" :value="2" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">搜索</el-button>
      </el-form-item>
    </el-form>

    <div class="table">
      <div class="big" v-for="(item, index) in  tableData " :key="index">
        <div class="father" style="line-height: 40px;">
          父订单号：<span>{{ item.tid }}</span> <span style="margin-left: 20px;">{{ item.shopTitle }}</span>
        </div>
        <div v-for="(items, indexs) in  item.refundOrderList " :key="indexs"
          style="display: flex; border-bottom: 1px dashed #ccc;align-items:flex-start;">
          <div>
            <el-image style="width: 100px; height: 100px;margin-top: 15px;" :src="items.picPath" fit="fill" />
          </div>
          <div class="contentRight">
            <p><span>子订单号：{{ items.oid }}</span><span>买家退款时间：{{ items.created }}</span><span>订单的商品数量：{{ items.
      buyNum }}</span></p>
            <p><span>{{ items.sku }}</span><span>退回数量：{{ items.
      num }}</span></p>
            <p><span style="color: red;  font-weight: 700;">{{
      items.isPass == 0 ? '未处理' : items.isPass == 1 ? '通过' : items.isPass == 0 ? '未通过' : '' }}</span>
              <span v-if="items.isPass !== 1">
                <el-button @click=" inDestructionArea(items.id)">放入销毁区</el-button> <el-button
                  @click="rejectionShop(items.id)">拒收货物</el-button>
              </span>
            </p>
          </div>
          <div>
            <p>
              <span>发给买家的运单号：{{ items.invoiceNo }}</span>
            </p>
            <p>
              <span>买家退回的运单号：{{ items.sid }}</span>
            </p>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="page">
    <el-pagination v-model:current-page="currentPage4" v-model:page-size="pageSize4" :page-sizes="[10, 50, 100]"
      layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" />
  </div>
</template>

<script setup>
import { ref, onBeforeMount } from 'vue'
import { afterHandleOrderlist, afterHandleOrderdestruction, afterHandleOrderrefusal } from '@/api/index'
import { ElMessage } from 'element-plus'
import { useAlertsStore } from '@/store/index'
const store = useAlertsStore()
// const form = ref({})
const pageForm = ref({
  warehouseId: -1,
  tid: '',
  oid: '',
  isPass: 1,
  pageSize: 10,
  pageNum: 1
})
const onSubmit = () => {
  console.log('submit!')
  getList()
}
onBeforeMount(() => {
  store.wareHouseSelect()
  getList()
})
// table多选
// const multipleSelection = ref([])
// const handleSelectionChange = (val) => {
//   multipleSelection.value = val
// }
const getList = () => {
  afterHandleOrderlist(pageForm.value).then(res => {
    const { data: { data } } = res
    total.value = data.total
    tableData.value = data.list
  })
}
// 分页
const tableData = ref([])
const currentPage4 = ref(1)
const pageSize4 = ref(10)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
  pageForm.value.pageSize = val
  getList()
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  pageForm.value.pageNum = val
  getList()
}
// 销毁
const inDestructionArea = (id) => {
  afterHandleOrderdestruction({ id: id }).then(res => {
    getList()
    ElMessage.success('操作成功')
  })
}
// 拒收
const rejectionShop = (id) => {
  afterHandleOrderrefusal({ id: id }).then(res => {
    getList()
    ElMessage.success('操作成功')
  })
}
</script>

<style lang='less' scoped>
.big {
  border-top: 1px solid #ccc;
  border-bottom: 1px solid #ccc;
}

.contentRight p span {
  display: inline-block;
  margin: 0 40px;
}

.contentRight p {
  line-height: 20px;
}
</style>
